﻿using MediatR;
using S.Eartag.API.Application.Command.LamBingCommand;
using S.Eartag.Domain;
using S.Eartag.Infrastructure.Interface;

namespace S.Eartag.API.Application.CommandHandlers.LamBingCommandHandler
{
    public class LamBingUpdatesCommandHandler : IRequestHandler<LamBingUpdatesCommand, int>
    {
        private readonly ILamBingRepository lamBingRepository;

        public LamBingUpdatesCommandHandler(ILamBingRepository lamBingRepository)
        {
            this.lamBingRepository = lamBingRepository;
        }

        public async Task<int> Handle(LamBingUpdatesCommand request, CancellationToken cancellationToken)
        {
            var res = lamBingRepository.GetValues(x => x.EarNumber == request.card).Result.FirstOrDefault();
            res.UseCondition= UseCondition.已使用;
            return await lamBingRepository.Update(res);
        }
    }
}
